class Solution {
    struct node{

        vector<int> classs;
        double passPer;
    };
    struct cmp{

        bool operator () (const node& p1,const node& p2){
            
           double a1=p1.classs[0],b1=p1.classs[1];
           double a2=p2.classs[0],b2=p2.classs[1];
           return ((a1+1)/(b1+1)-a1/b1)<((a2+1)/(b2+1)-a2/b2);
        }
    };
public:
    double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) {
        
        int n=classes.size();
        vector<double> db(n);
        priority_queue<node,vector<node>,cmp> q;
        for(int i=0;i<n;++i){
            double passPer=1.0*classes[i][0]/classes[i][1];
            q.push({classes[i],passPer});
        }
        double sum=0;
        while(extraStudents){
            auto u=q.top();
            q.pop();
            u.passPer=(1.0*u.classs[0]+1)/(u.classs[1]+1);
            q.push({{u.classs[0]+1,u.classs[1]+1},u.passPer});
            --extraStudents;
        }
        while(q.size()){
            auto u=q.top();
            q.pop();
            sum+=u.passPer;
        }
        
        return sum/n;
    }
};
